package com.codingman.thymeleafdemo2;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;

@WebServlet("/listform")
public class ListFormServlet extends HttpServlet {
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		List<Employee> list = EmployeeDao.getAllEmployees();
		
		WebContext ctx = new WebContext(request, response, request.getServletContext());
		ctx.setVariable("employees", list);
        
		TemplateEngine engine = ThymeleafUtil.getTemplateEngine(request.getServletContext());
		engine.process("list", ctx, response.getWriter());
	}
}
